type
    edge=record
        next:array[0..26]of longint;
        cnt:longint;
    end;
var
    ch:char; s:string;
    i,n,u,v,cnt,node,q:longint;
    h,rt,dep:array[0..100100]of longint;
    g,nxt:array[0..200100]of longint;
    str:array[0..200100]of string;
    f:array[0..100100,0..20]of longint;
    tree:array[0..1000100]of edge;

procedure add(u,v:longint; s:string);
begin
    inc(cnt); g[cnt]:=v; str[cnt]:=s; nxt[cnt]:=h[u]; h[u]:=cnt;
end;

function insert(t:longint; s:string; i:longint):longint;
var nt,k:longint;
begin
    inc(node); nt:=node; tree[nt]:=tree[t];
    if i>length(s) then inc(tree[nt].cnt)
    else
        begin
            k:=ord(s[i])-ord('a')+1;
            inc(tree[nt].cnt);
            tree[nt].next[k]:=insert(tree[nt].next[k],s,i+1);
        end;
    exit(nt);
end;

procedure dfs(x,fa,t:longint);
var i,k:longint;
begin
    f[x,0]:=fa; rt[x]:=t;
    for i:=0 to 19 do
        if f[x,i]<>0 then f[x,i+1]:=f[f[x,i],i];
    i:=h[x];
    while i<>0 do
        begin
            k:=g[i];
            if k<>fa then
                begin
                    dep[k]:=dep[x]+1; dfs(k,x,insert(t,str[i],1));
                end;
            i:=nxt[i];
        end;
end;

function lca(u,v:longint):longint;
var i,t:longint;
begin
    if dep[u]<dep[v] then
        begin t:=u; u:=v; v:=t; end;
    for i:=20 downto 0 do
        if (f[u,i]<>0)and(dep[f[u,i]]>=dep[v]) then u:=f[u,i];
    if u=v then exit(u);
    for i:=20 downto 0 do
        if (f[u,i]<>0)and(f[v,i]<>0)and(f[u,i]<>f[v,i]) then
            begin u:=f[u,i]; v:=f[v,i]; end;
    exit(f[u,0]);
end;

function count(u:longint; s:string):longint;
var t,i:longint;
begin
    t:=rt[u]; i:=1;
    while i<=length(s) do
        begin
            if t=0 then exit(0);
            t:=tree[t].next[ord(s[i])-ord('a')+1];
            inc(i);
        end;
    if t=0 then exit(0) else exit(tree[t].cnt);
end;

begin
    assign(input,'strings.in'); reset(input);
    assign(output,'strings.out'); rewrite(output);
    readln(n);
    for i:=1 to n-1 do
        begin
            read(u,v); read(ch); readln(s);
            add(u,v,s); add(v,u,s);
        end;
    dep[1]:=1; dfs(1,0,0); readln(q);
    for i:=1 to q do
        begin
            read(u,v); read(ch); readln(s);
            writeln(count(u,s)+count(v,s)-2*count(lca(u,v),s));
        end;
    close(input); close(output);
end.